import os
import sys
import argparse

folders = []

parser = argparse.ArgumentParser()
parser.add_argument('-p', '--project', default='e21', help='project info')

args = parser.parse_args()
print(args.project)

if 'e21' in args.project:
    target = 'freedom_e21-oe-linux'
elif 'u540' in args.project:
    target = 'freedom_u540-oe-linux'
elif 'boot' in args.project:
    target = 'freedom_u540-c000-bootloader'
else:
    target = 'freedom_e21-oe-linux'

WORK_DIR = '%s/SiFive-OE/riscv-sifive/build/tmp-glibc/work/%s/u-boot/1_2019.07-r0' % (os.getenv('HOME'), target)

print('Current dir:%s' % os.getcwd())
print('Work dir:%s' % WORK_DIR)
#for root, dirs, files in os.walk(os.getcwd()):
#for root, dirs, files in os.walk(WORK_DIR):
#    for dir in dirs:
#        full_path = os.path.join(root, dir)
#        #b,f = os.path.splitext(full_path)
#        ##if '.git' in f:
#        #print(f)
#        if full_path not in folders:
#            folders.append(full_path)
#
#for i in range(len(folders)):
#    print('%5d: %s' % (i, folders[i]))
#
#target_folder = int(raw_input('Select the target folder index:'))
#print(target_folder)
#os.chdir(folders[target_folder])

u_boot_dirs = [
    'build',
    'build/arch/riscv/dts',
    'git',
    'temp'
]


os.system('ls %s' % WORK_DIR)
for d in u_boot_dirs:
    print('%s/%s' % (WORK_DIR, d))


u_boot_files = [
    'riscv-sifive/meta-sifive/conf/machine/freedom-u540.conf',
    'riscv-sifive/meta-sifive/wic/freedom-u540-fsbl-opensbi.wks'
]

for f in u_boot_files:
    print('%s' % (f))




